package cz.zcu.fav.rat.dataaccess.service.impl;

import java.util.Collection;
import java.util.List;

import cz.zcu.fav.rat.dataaccess.dao.GenericDAO;
import cz.zcu.fav.rat.dataaccess.service.GenericDataAccessService;

public abstract class GenericDataServiceImpl<T, DAO extends GenericDAO<T, Integer>>
		implements GenericDataAccessService<T, GenericDAO<T, Integer>>
{

	DAO dao;

	public GenericDataServiceImpl(DAO dao)
	{
		this.dao = dao;
	}

	@Override
	public Integer create(T newInstance)
	{
		return dao.create(newInstance);
	}

	@Override
	public void update(T transientObject)
	{
		dao.update(transientObject);
	}

	@Override
	public void delete(T persistentObject)
	{
		dao.delete(persistentObject);
	}

	@Override
	public T get(Integer id)
	{
		return dao.read(id);
	}

	@Override
	public List<T> getAll()
	{
		return dao.getAll();
	}

	@Override
	public void saveOrUpdate(T persistentObject)
	{
		dao.saveOrUpdate(persistentObject);
	}

	@Override
	public T merge(T object)
	{
		return dao.merge(object);
	}
	
	public void deleteCollection(Collection<T> data)
	{
		for (T object : data)
		{
			delete(object);
		}
	}
}
